// Function.prototype.test = function () {
//     console.log('test', this)
// }
// // Function.prototype.test()

// let fn = function () {
//     console.log('fn')
// }
// fn.test()
console.log('-------------call------------')
let fn = function (val, val2) {
    console.log('fn', val, val2, this)
}
fn.call({x: 4}, 'test', 'test2')
Function.prototype.mycall = function (ctx, ...arg) {
    ctx.fn = this
    ctx.fn(...arg)
    delete ctx.fn
}
fn.mycall({x: 4}, 'test', 'test2')

console.log('-------------apply------------')
fn.apply({x: 4}, ['test', 'test2'])
Function.prototype.myapply = function (ctx, arg) {
    ctx.fn = this
    ctx.fn(...arg)
    delete ctx.fn
}
fn.myapply({x: 4}, ['test', 'test2'])

console.log('-------------bind------------')
fn.bind({ x:5 }, 'test', 'test2')()
Function.prototype.mybind = function (ctx, ...arg) {
    ctx.fn = this
    // return ctx.fn(...arg)
    return function () {
        ctx.fn(...arg)
        delete ctx.fn
    }
}
fn.mybind({ x:5 }, 'test', 'test2')()